#include "ProgBar.h"
#include "ResourceManagers.h"

ProgBar::ProgBar(sf::Image *bar, sf::Image *frame, sf::Vector2f pos, float opacity){
	m_bar=new Sprite(*bar);
	m_frame=new Sprite(*frame);
	m_bar->SetScale(0.5f,0.5f);
	m_frame->SetScale(0.5f, 0.5f);
	m_bar->SetColor(Color(255,255,255,opacity));
	//m_frame->SetColor(Color(255,255,255,157));
	SetPosition(pos);
}


ProgBar::~ProgBar(void)
{
}

void ProgBar::SetMaxMin(float _max, float _min){
	max=_max;
	min=_min;
}

void ProgBar::SetValue(float val){

	IntRect sub;
	sub.Left=0;
	sub.Top=0;
	sub.Bottom=m_bar->GetImage()->GetHeight();
	float scale=(val-min)/(max-min);
	if( scale<0)
		sub.Right=0;
	if(scale>1)
		sub.Right=1;

	sub.Right= scale* m_bar->GetImage()->GetWidth();
	m_bar->SetSubRect(sub);
}

void ProgBar::Draw(RenderWindow *wnd){

	wnd->Draw(*m_bar);
	wnd->Draw(*m_frame);

}
void ProgBar::Update(float dt){

}

void ProgBar::SetPosition(Vector2f pos){


	m_frame->SetPosition(pos);
	m_bar->SetPosition(pos);


}
